package org.yxing.palpalgps.adapter;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.widget.BaseAdapter;

abstract public class JSONArrayAdapter extends BaseAdapter{
    
    protected JSONArray data;
    /**
     * set json array data
     * @param data
     */
    public void setData(JSONArray data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return (data == null) ? 0 : data.length();
    }

    @Override
    public JSONObject getItem(int position) {
        JSONObject item = null;
        try {
            item = data.getJSONObject(position);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        
        return item;
    }
}
